package com.xiaobo.framework.service;

import com.xiaobo.framework.api.bean.Message;
import com.xiaobo.framework.repository.MessageDao;
;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: <a href="get_xiaobo@163.com">Josh_Xu</a>
 * @description:
 * @create: 2020-04-24 0:30
 **/
@Service
public class MessageService {

    @Autowired
    private MessageDao messageDao;

    public List<Message> queryMessageList(Long fromId, Long toId, Integer page, Integer rows) {
        List<Message> messageList = this.messageDao.findListByFromAndTo(fromId, toId, page, rows);
       /* for (Message message : messageList) {
            if (message.getStatus().intValue() == 1) {
                this.messageDao.updateMessageState(message.getId(), 1);
            }
        }*/

        messageList.forEach(list -> {
            if (list.getStatus().intValue() == 1) {
                this.messageDao.updateMessageState(list.getId(), 1);
            }
        });
        return messageList;
    }
}
